package com.agileboot.attendance.domain.personnel.dto;

import cn.hutool.core.bean.BeanUtil;
import com.agileboot.attendance.domain.personnel.db.AttPersonnelEntity;
import com.agileboot.attendance.domain.supplier.db.AttSupplierEntity;
import com.agileboot.common.annotation.ExcelColumn;
import com.agileboot.common.annotation.ExcelSheet;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <p>
 * 人员信息DTO
 * </p>
 *
 * @author agileboot
 * @since 2023-03-14
 */
@Data
@NoArgsConstructor
@ApiModel(value = "人员信息")
@ExcelSheet(name = "人员列表")
public class PersonnelDTO {

    @ApiModelProperty("人员ID")
    @ExcelColumn(name = "人员ID")
    private Long personnelId;

    @ApiModelProperty("人员姓名")
    @ExcelColumn(name = "人员姓名")
    private String personnelName;

    @ApiModelProperty("人员编码")
    @ExcelColumn(name = "人员编码")
    private String personnelCode;

    @ApiModelProperty("身份证号")
    @ExcelColumn(name = "身份证号")
    private String idNumber;

    @ApiModelProperty("所属供应商ID")
    @ExcelColumn(name = "供应商ID")
    private Long supplierId;

    @ApiModelProperty("所属供应商名称")
    @ExcelColumn(name = "供应商名称")
    private String supplierName;

    @ApiModelProperty("性别（0男 1女 2未知）")
    private String gender;

    @ApiModelProperty("性别名称")
    @ExcelColumn(name = "性别")
    private String genderName;

    @ApiModelProperty("出生日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ExcelColumn(name = "出生日期")
    private Date birthDate;

    @ApiModelProperty("手机号码")
    @ExcelColumn(name = "手机号码")
    private String phoneNumber;

    @ApiModelProperty("邮箱")
    @ExcelColumn(name = "邮箱")
    private String email;

    @ApiModelProperty("级别（01初级 02中级 03高级 04专家）")
    private String level;

    @ApiModelProperty("级别名称")
    @ExcelColumn(name = "级别")
    private String levelName;

    @ApiModelProperty("职位（01开发 02测试 03运维 04项目经理）")
    private String position;

    @ApiModelProperty("职位名称")
    @ExcelColumn(name = "职位")
    private String positionName;

    @ApiModelProperty("人月单价")
    @ExcelColumn(name = "人月单价")
    private BigDecimal monthlyRate;

    @ApiModelProperty("入场日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ExcelColumn(name = "入场日期")
    private Date entryDate;

    @ApiModelProperty("离场日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ExcelColumn(name = "离场日期")
    private Date leaveDate;

    @ApiModelProperty("状态（0在岗 1离场 2休假）")
    private String status;

    @ApiModelProperty("状态名称")
    @ExcelColumn(name = "状态")
    private String statusName;

    @ApiModelProperty("关联用户ID")
    @ExcelColumn(name = "关联用户ID")
    private Long userId;

    @ApiModelProperty("备注")
    @ExcelColumn(name = "备注")
    private String remark;

    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ExcelColumn(name = "创建时间")
    private Date createTime;

    /**
     * 构造函数，从实体类转换
     *
     * @param personnel 人员实体类
     */
    public PersonnelDTO(AttPersonnelEntity personnel) {
        if (personnel != null) {
            BeanUtil.copyProperties(personnel, this);

            // 性别名称
            if ("0".equals(personnel.getGender())) {
                this.genderName = "男";
            } else if ("1".equals(personnel.getGender())) {
                this.genderName = "女";
            } else {
                this.genderName = "未知";
            }

            // 级别名称
            if ("01".equals(personnel.getLevel())) {
                this.levelName = "初级";
            } else if ("02".equals(personnel.getLevel())) {
                this.levelName = "中级";
            } else if ("03".equals(personnel.getLevel())) {
                this.levelName = "高级";
            } else if ("04".equals(personnel.getLevel())) {
                this.levelName = "专家";
            }

            // 职位名称
            if ("01".equals(personnel.getPosition())) {
                this.positionName = "开发";
            } else if ("02".equals(personnel.getPosition())) {
                this.positionName = "测试";
            } else if ("03".equals(personnel.getPosition())) {
                this.positionName = "运维";
            } else if ("04".equals(personnel.getPosition())) {
                this.positionName = "项目经理";
            }

            // 状态名称
            if ("0".equals(personnel.getStatus())) {
                this.statusName = "在岗";
            } else if ("1".equals(personnel.getStatus())) {
                this.statusName = "离场";
            } else if ("2".equals(personnel.getStatus())) {
                this.statusName = "休假";
            }
        }
    }

    /**
     * 构造函数，从实体类转换
     *
     * @param personnel 人员实体类
     * @param supplier 供应商实体类
     */
    public PersonnelDTO(AttPersonnelEntity personnel, AttSupplierEntity supplier) {
        this(personnel);
        if (supplier != null) {
            this.supplierName = supplier.getSupplierName();
        }
    }
} 